package cn.tangsihai.hrm.service.impl;

import cn.tangsihai.hrm.constant.Constants;
import cn.tangsihai.hrm.domain.Meal;
import cn.tangsihai.hrm.mapper.MealMapper;
import cn.tangsihai.hrm.service.IMealService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 套餐表 服务实现类
 * </p>
 *
 * @author sihai.tang
 * @since 2021-11-22
 */
@Service
public class MealServiceImpl extends ServiceImpl<MealMapper, Meal> implements IMealService {
    @Autowired
    private MealMapper mealMapper;

    @Override
    public void saveLoginMeal(Long id, Long mealId) {
        // 校验参数合理性
        if (id == null || mealId == null){
            throw new RuntimeException("参数不正确");
        }
        // 准备数据
        Date expiration = DateUtils.addDays(new Date(), 7);
        // 设置状态
        int state = Constants.LoginMeal.STATE_NO_PAY;
        // 保存到数据库
        mealMapper.saveLoginMeal(mealId, id, expiration, state);
    }
}
